<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
  
  <head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" th:href="@{/pages/favicon.ico}" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" th:href="@{/pages/css/font.css}" href="./css/font.css">
    <link rel="stylesheet" th:href="@{/pages/css/xadmin.css}" href="./css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="./lib/layui/layui.js" th:src="@{/pages/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/pages/js/xadmin.js}" src="./js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a><cite>地区列表</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>

    <div class="x-body">
      <div class="layui-row">
      </div>
      <xblock>
        <button class="layui-btn" type="button" lay-filter="add" onclick="openAdd('添加平台地区','/manage/platformarea/toAdd')"><i class="layui-icon"></i>添加</button>
        <span class="x-right" style="line-height:40px">共有数据：<span th:text="${#lists.size(platformareaList)}"></span> 条</span>
      </xblock>
      <form class="layui-form layui-col-md12 x-so" th:action="@{/manage/platformarea/toList}" method="post">
      <table class="layui-table">
        <thead>
          <tr>
            <th>
              <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th>地区名称</th>
            <th>是否启用</th>
            <th>操作</th>
            </tr>
        </thead>
        <tbody>
          <tr th:each="area:${platformareaList}">
            <td>
              <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>
            </td>
            <td th:text="${area?.areaName}"></td>
            <td><input type="checkbox" lay-filter="isUsed" th:attr="fid=${area.id}" lay-skin="switch" lay-text="启用|禁用" th:checked="${area?.delFlag=='0'}"></td>
            <td class="td-manage">
              <a title="删除" th:attr="aid=${area?.id}" onclick="area_del(this)" href="javascript:;">
                <i class="layui-icon">&#xe640;</i>
              </a>
            </td>
          </tr>
        </tbody>
      </table>
      </form>
      <div class="page" id="page">

      </div>
    </div>

    <script th:inline="javascript">
      layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var form = layui.form;

        //执行一个laydate实例
        laydate.render({
          elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
        });

          form.on('switch(isUsed)', function(data){
              var index = layer.msg('修改中，请稍候',{icon: 16,time:false,shade:0.8});
              setTimeout(function(){
                  layer.close(index);
                  var fid = $(data.elem).attr("fid");
                  $.post("/manage/platformarea/update",{"id":fid},function (data) {
                      layer.msg(data);
                  });
              },500);
          });

      });

      /*删除*/
      function area_del(obj){
          layer.confirm('确认要删除吗？',function(index){
              //发异步删除数据
              var aid = $(obj).attr("aid");
              $.post("/manage/platformarea/delete?id="+aid,"",function (result,status,jqxhr) {
                  if(jqxhr.status==200){
                      layer.msg(result,{icon:1,time:1000},function () {
                          $("form").submit();
                      });
                  }else{
                      layer.msg(result,{icon:2,time:1000});
                  }
              });

          });
      }

      function openAdd(title,url) {
          var w=($(window).width()*0.9);
          var h=($(window).height() - 50);
          layer.open({
              type: 2,
              area: [w+'px', h +'px'],
              fix: false, //不固定
              maxmin: true,
              shadeClose: true,
              shade:0.4,
              title: title,
              content: url
          });
      }
    </script>
  </body>

</html>